Skip to content

tests: Extend various test frameworks for postgres sinks - #40847

Draft
def- wants to merge 21 commits into
MaterializeInc:mainfrom
def-:pg-sink-roundtrip-tests
Draft

def- wants to merge 21 commits into
MaterializeInc:mainfrom
def-:pg-sink-roundtrip-tests

Conversation

@def-

@def- def- commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

On top of #39708

patrickwwbutler and others added 21 commits November 13, 2026 14:48
Parse, purify and plan Postgres sinks, add the PostgresSinkConnection
storage type, and teach the catalog and mz-deploy about the new sink
connection. The storage dataflow is left as an unimplemented stub.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The sink now stages each window in a session temporary table, so no
staging table sits next to the target table and nothing needs its name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wire up render_sink for Postgres sinks: an encode operator on every
worker feeding a write operator on one worker, chosen by hashing the
sink id. The write operator creates the target and progress tables under
an advisory lock, then claims the sink's progress row by bumping its
epoch, which fences off every earlier incarnation of the sink. A target
table without a primary key gets REPLICA IDENTITY FULL, so the sink can
delete from it even when a FOR ALL TABLES publication covers it.

The encode operator and the write loop are unimplemented stubs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement the encode operator and the staging half of the write loop.
Every worker encodes its share of the sink's updates as COPY BINARY
rows, tagged with the Materialize timestamp and a diff of 1 or -1. The
write operator opens one SERIALIZABLE transaction per timestamp window,
checks that the progress row still carries its epoch and the frontier it
expects, and streams the window's rows into a session temporary table
that ON COMMIT DELETE ROWS empties after every window.

Applying a staged window to the target table is an unimplemented stub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Complete the write loop. Each completed timestamp window is applied to
the target table in the transaction that staged it, and the new frontier
is recorded in materialize.sink_progress only while the row still
carries this incarnation's epoch. The persist progress shard is brought
up to that frontier after the commit, and reconciled forward at startup.

A keyed sink takes every key a window touches straight from its state
before the window to its state after it, with at most one INSERT, UPDATE
or DELETE per key, so a window holding several timestamps for one key
never puts the key in the target table twice. A keyless sink inserts and
retracts exact row multiplicities.

Adds unit tests, run against the database at POSTGRES_URL, for key
replacement, one operation per key, rejected windows, keyless
multiplicities and fencing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Assert that the target table is the only table the sink creates, with
the key as its primary key, now that staging happens in a session
temporary table. Check that the progress row records an epoch, that a
restart claims a newer one, and that a progress row claimed by a newer
version of the sink stalls this one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run the Postgres sink testdrive files from a pg-sink composition with
its own CI step, so they only start the services they need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check that a sink on a cluster with several replicas applies each update
exactly once, and keeps running when a replica is dropped or added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Re-ingest sink targets and compare complete rows, including duplicates, across updates and replica changes. Run the coverage in the existing testdrive composition and wait for sink progress before inspecting target tables.
Sink the existing Postgres source into keyed or keyless targets and re-ingest them for the generated workload comparison. Wait for the sink frontier before the recency read so an empty result cannot pass before the sink catches up.
Generate keyed and keyless Postgres sinks and exercise creation, dropping, renaming, SET FROM, and shared sink metadata actions. Reuse the existing sink actions and track cleanup during schema churn.
Create keyed and keyless sink/readback pairs in every check phase and compare complete row multisets after disruptions. Gate the check on the first version with Postgres sink support.
Exercise disconnections, revoked write privileges, and dropped or altered targets for keyed and keyless sinks. Verify namespaced errors and exact readback after restoring connectivity or permissions and restarting the replica.
Check that standby generations leave sink epochs unchanged while the old leader continues writing. Verify keyed and keyless roundtrips and newer epochs after promotion, including forced catalog migration.
Roundtrip a 256 MiB keyed or keyless snapshot under a 2 GiB writer limit. Block the destination during an insert burst, verify row multiplicities and payloads, and repeat validation after restarting Materialize and clusterd.
Reuse the existing sink capability and generated view validation across randomized scenarios. Source PostgreSQL targets back into Materialize so the model checks updates and recovery. Add testdrive roundtrips for global aggregates and a keyless column named n.

Keep failing assertions enabled and include sink status errors in readiness checks so CI exposes product bugs without changing the sink implementation.
Reuse the existing PostgreSQL connections to verify keyed and keyless sink readback, duplicate preservation, mutations, and recovery after an SSH failure. Exercise the same fixture with TLS.

Roundtrip synthetic private data with credentials stored in a secret, then trigger constraint and authentication errors. Assert that sink status history and Materialize logs do not contain private values, keeping product failures enabled for CI.
Check bounded-memory keys and payloads in one query so a stale readback cannot hide a corrupt final payload. Preserve raw Postgres readback rows and compare sink-derived views with their inputs using bidirectional EXCEPT ALL, including empty-input states.

Use to_regclass in asynchronous schema polls and keep the keyless sink alive across restart to detect replayed rows. Run the known-failing aggregate case after the restart and fencing checks so those assertions still execute.
The state multi-put failpoint belongs to the v1 upsert operator. Select that operator in the failing deployment so the source reaches stalled before promotion and the existing recovery assertion remains meaningful.
@def- def- changed the title storage: add Postgres sinks with roundtrip coverage tests: Extend various test frameworks for postgres sinks Nov 18, 2026
@def-

def- commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@patrickwwbutler This seems to have foundan issue, see https://buildkite.com/materialize/nightly/builds/18770. There are syntax errors for hte generated PRIMARY KEY ()

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants